from selenium.webdriver.common.by import By
from pages.base_page import Page


class ConversionPage(Page):

    ele_title = (By.XPATH, u"//h3[text()='Conversions']")
    ele_img = (By.XPATH, u"//img[@alt='Conversions Introduction']")
    ele_unlock_button = (By.XPATH, u"//span[text()='Unlock This Feature']")

    new_conversion_action_button = (By.ID, u'table-conversionAction-button-new')
    new_conversion_action_name_text = (By.ID, u'form-conversionAction-input-name')
    if_enable_button = (By.XPATH, u"//div[text()='Enable']")
    api_button = (By.XPATH, u"//button[@value='API']")
    save_button = (By.XPATH, u"//span[text()='Save']")

    delete_conversion = (By.XPATH, u"//tr[@id='drag-0']/td[@data-tag='operation']/div/button[2]")
    confirm_delete = (By.XPATH, u"//span[text()='Delete']")

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_conversions_page_when_has_conversions_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.new_conversion_action_button).is_enabled()


    def check_new_conversion(self):
        self.click(self.new_conversion_action_button)
        self.input_text(self.new_conversion_action_name_text, 'autotest')
        self.click(self.if_enable_button)
        self.click(self.api_button)
        self.click(self.save_button)

    def check_delete_conversion(self):
        self.click(self.delete_conversion)
        self.click(self.confirm_delete)

    def check_conversions_page_when_no_conversions_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_img).is_enabled()
        self.find_element(*self.ele_unlock_button).is_enabled()



